home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1998 June / SGI Freeware 1998 June.iso / dist / fw_ATxgopher.idb / usr / freeware / src / xgopher.1.3 / error.c.z / error.c
C/C++ Source or Header  |  1998-01-21  |  9KB  |  387 lines

  1. /* error.c
  2.    functions to handle error and notice popups */
  3.  
  4.      /*---------------------------------------------------------------*/
  5.      /* Xgopher        version 1.3     08 April 1993                  */
  6.      /*                version 1.2     20 November 1992               */
  7.      /*                version 1.1     20 April 1992                  */
  8.      /*                version 1.0     04 March 1992                  */
  9.      /* X window system client for the University of Minnesota        */
  10.      /*                                Internet Gopher System.        */
  11.      /* Allan Tuchman, University of Illinois at Urbana-Champaign     */
  12.      /*                Computing and Communications Services Office   */
  13.      /* Copyright 1992, 1993 by                                       */
  14.      /*           the Board of Trustees of the University of Illinois */
  15.      /* Permission is granted to freely copy and redistribute this    */
  16.      /* software with the copyright notice intact.                    */
  17.      /*---------------------------------------------------------------*/
  18.  
  19.  
  20. #include <stdio.h>
  21. #include <X11/Intrinsic.h>
  22. #include <X11/StringDefs.h>
  23.  
  24. #include <X11/Xaw/Command.h>
  25. #include <X11/Xaw/Dialog.h>
  26. #include <X11/Shell.h>
  27.  
  28. #include "osdep.h"
  29. #include "error.h"
  30. #include "xglobals.h"
  31. #include "gui.h"
  32. #include "bitmaps/sadxgopher.xbm"
  33. #include "bitmaps/xgopher.xbm"
  34.  
  35. static Widget    topLevel;
  36. Widget        errorDialogShell,
  37.         errorDialog;
  38. Widget        errorDialogLabel;
  39. Widget        errorOkButton;
  40. Pixmap        errorPixmap = None;
  41.  
  42. int        width;
  43.  
  44. Widget        infoDialogShell,
  45.         infoDialog;
  46. Widget        infoDialogLabel;
  47. Pixmap        infoPixmap = None;
  48.  
  49.  
  50. #define INFO_POPUP_NAME        "infoPopup"
  51.                 /* default values */
  52. static popupPosResources    placementInfo = {
  53.     /* position with the left, bottom corner near the pointer */
  54.     from_pointer, 0, 0, justify_top_left, justify_bottom_right, True, True
  55.     };
  56.  
  57. #define ERROR_POPUP_NAME    "errorPopup"
  58.                 /* default values */
  59. static popupPosResources    placementError = {
  60.     /* position with the left, bottom corner near the pointer */
  61.     from_pointer, 0, 0, justify_top_left, justify_bottom_right, True, True
  62.     };
  63.  
  64. #define FATAL_POPUP_NAME    "fatalErrorPopup"
  65.                 /* default values */
  66. static popupPosResources    placementFatal = {
  67.     /* position centered on the screen */
  68.     from_screen, 50, 50, justify_center, justify_center, True, True
  69.     };
  70.  
  71.  
  72.  
  73.  
  74. /* errorOkProc
  75.    User has read and accepted the error */
  76.  
  77. static void
  78. errorOkProc(w, client_data, call_data)
  79. Widget        w;
  80. XtPointer    client_data, call_data;
  81. {
  82.     XtPopdown(errorDialogShell);
  83.  
  84.     return;
  85. }
  86.  
  87.  
  88. /* errorExitProc
  89.    Fatal errors exit here */
  90.  
  91. static void
  92. errorExitProc(w, client_data, call_data)
  93. Widget        w;
  94. XtPointer    client_data, call_data;
  95. {
  96.     XtPopdown(errorDialogShell);
  97.  
  98.     closeGUIandQuit(1);
  99. }
  100.  
  101.  
  102. /* AckError
  103.    action procedure to acknowledge an error.
  104.    Capitalization is for Xt convention. */
  105.  
  106. static void
  107. AckError(w, event, params, numParams)
  108. Widget        w;
  109. XEvent        *event;
  110. String        *params;
  111. Cardinal    *numParams;
  112. {
  113.     XtCallCallbacks(errorOkButton, XtNcallback, NULL);
  114. }
  115.  
  116.  
  117. /* makeErrorDialog
  118.    create popup dialog for reporting errors */
  119.  
  120. void
  121. makeErrorDialog(top)
  122. Widget    top;
  123. {
  124.     Arg        args[10];
  125.     Cardinal    n = 0;
  126.     static XtActionsRec    actionsTable[] = {
  127.                 {"ackError",   AckError}
  128.                 };
  129.  
  130.     topLevel = top;
  131.  
  132.     XtAppAddActions(appcon, actionsTable, XtNumber(actionsTable));
  133.  
  134.     n = 0;
  135.     XtSetArg(args[n], XtNtitle, "Xgopher error");  n++;
  136.     errorDialogShell = XtCreatePopupShell("errorDialogShell", 
  137.                     transientShellWidgetClass,
  138.                     topLevel, args, n);
  139.  
  140.     errorPixmap = XCreatePixmapFromBitmapData (XtDisplay(topLevel),
  141.                 RootWindowOfScreen(XtScreen(topLevel)),
  142.                     (char *)sadxgopher_bits,
  143.                     sadxgopher_width, sadxgopher_height,
  144.                     BlackPixelOfScreen(XtScreen(topLevel)),
  145.                     WhitePixelOfScreen(XtScreen(topLevel)),
  146.                     DefaultDepthOfScreen(XtScreen(topLevel))
  147.                     );
  148.  
  149.     n = 0;
  150.     XtSetArg(args[n], XtNlabel, "Xgopher error");  n++;
  151.     if (errorPixmap != None) {
  152.         XtSetArg(args[n], XtNicon, errorPixmap);  n++;
  153.     }
  154.     errorDialog= XtCreateManagedWidget("errorDialog", 
  155.                     dialogWidgetClass,
  156.                     errorDialogShell, args, n);
  157.         {
  158.             XFontStruct    *textFontStruct;
  159.             int        direction, ascent, descent;
  160.             XCharStruct    overall;
  161.             Position    topMargin, bottomMargin;
  162.  
  163.             errorDialogLabel = XtNameToWidget(errorDialog, "label");
  164.  
  165.             n=0;
  166.             XtSetArg(args[n], XtNfont, &textFontStruct);  n++;
  167.             XtGetValues(errorDialogLabel, args, n);
  168.             XTextExtents(textFontStruct, "mljf", 4,
  169.                 &direction, &ascent, &descent, &overall);
  170.  
  171.             width = overall.width*20;
  172.         }
  173.  
  174.     errorOkButton = XtCreateManagedWidget("ok", commandWidgetClass, 
  175.                     errorDialog, NULL, (Cardinal) 0);
  176.         XtAddCallback(errorOkButton, XtNcallback, errorOkProc, NULL);
  177.  
  178.  
  179.         /* for ICCCM window manager protocol complience */
  180.  
  181.         XtOverrideTranslations (errorDialogShell,
  182.             XtParseTranslationTable ("<Message>WM_PROTOCOLS: ackError()"));
  183.  
  184.     /* find the popup placement for this shell */
  185.  
  186.     {
  187.     popupPosResources *resourcePlacement;
  188.  
  189.     resourcePlacement = getPopupPosResources(
  190.             ERROR_POPUP_NAME, POPUP_POS_CLASS, &placementError);
  191.     bcopy( (char *) resourcePlacement, (char *) &placementError,
  192.                 sizeof(popupPosResources) );
  193.  
  194.     resourcePlacement = getPopupPosResources(
  195.             FATAL_POPUP_NAME, POPUP_POS_CLASS, &placementFatal);
  196.     bcopy( (char *) resourcePlacement, (char *) &placementFatal,
  197.                 sizeof(popupPosResources) );
  198.     }
  199.  
  200. }
  201.  
  202.  
  203. /* displayError
  204.    enable popup dialog for saving files */
  205.  
  206. void
  207. displayError(errorText, fatal)
  208. char    *errorText;
  209. Boolean    fatal;
  210. {
  211.     Arg        args[10];
  212.     Cardinal    n = 0;
  213.  
  214.  
  215.     n = 0;
  216.     XtSetArg(args[n], XtNlabel, errorText);  n++;
  217.     XtSetValues(errorDialog, args, n);
  218.  
  219.     n = 0;
  220.     XtSetArg(args[n], XtNwidth, width);  n++;
  221.     XtSetValues(errorDialogLabel, args, n);
  222.  
  223.  
  224.     if (fatal) {
  225.         XtAddCallback(errorOkButton, XtNcallback, errorExitProc, NULL);
  226.         positionAPopup(errorDialogShell, topLevel, &placementFatal);
  227.     } else {
  228.         positionAPopup(errorDialogShell, topLevel, &placementError);
  229.     }
  230.  
  231.  
  232.     XtPopup(errorDialogShell, XtGrabExclusive);
  233.  
  234.         /* for ICCCM window manager protocol complience */
  235.  
  236.         (void) XSetWMProtocols (XtDisplay(errorDialogShell),
  237.              XtWindow(errorDialogShell), &wmDeleteAtom, 1);
  238.  
  239.     return;
  240. }
  241.  
  242. /* info popup and stuff */
  243.  
  244. /* infoOkProc
  245.    User has read and accepted the information */
  246.  
  247. static void
  248. infoOkProc(w, client_data, call_data)
  249. Widget        w;
  250. XtPointer    client_data, call_data;
  251. {
  252.     XtPopdown(infoDialogShell);
  253.  
  254.     return;
  255. }
  256.  
  257.  
  258. /* AckInfo
  259.    action procedure to acknowledge an information popup.
  260.    Capitalization is for Xt convention. */
  261.  
  262. static void
  263. AckInfo(w, event, params, numParams)
  264. Widget        w;
  265. XEvent        *event;
  266. String        *params;
  267. Cardinal    *numParams;
  268. {
  269.     infoOkProc(w, NULL, NULL);
  270. }
  271.  
  272.  
  273. /* makeInfoDialog
  274.    create popup dialog for reporting infos */
  275.  
  276. void
  277. makeInfoDialog(top)
  278. Widget    top;
  279. {
  280.     Widget        infoOkButton;
  281.     Arg        args[10];
  282.     Cardinal    n = 0;
  283.  
  284.     static XtActionsRec    actionsTable[] = {
  285.                 {"ackInfo",   AckInfo}
  286.                 };
  287.  
  288.     topLevel = top;
  289.  
  290.     XtAppAddActions(appcon, actionsTable, XtNumber(actionsTable));
  291.  
  292.     n = 0;
  293.     XtSetArg(args[n], XtNtitle, "Xgopher information");  n++;
  294.     infoDialogShell = XtCreatePopupShell("infoDialogShell", 
  295.                     transientShellWidgetClass,
  296.                     topLevel, args, n);
  297.  
  298.     infoPixmap = XCreatePixmapFromBitmapData (XtDisplay(topLevel),
  299.                 RootWindowOfScreen(XtScreen(topLevel)),
  300.                     (char *)xgopher_bits,
  301.                     xgopher_width, xgopher_height,
  302.                     BlackPixelOfScreen(XtScreen(topLevel)),
  303.                     WhitePixelOfScreen(XtScreen(topLevel)),
  304.                     DefaultDepthOfScreen(XtScreen(topLevel))
  305.                     );
  306.  
  307.     n = 0;
  308.     XtSetArg(args[n], XtNlabel, "Xgopher information");  n++;
  309.     if (infoPixmap != None) {
  310.         XtSetArg(args[n], XtNicon, infoPixmap);  n++;
  311.     }
  312.     infoDialog= XtCreateManagedWidget("infoDialog", 
  313.                     dialogWidgetClass,
  314.                     infoDialogShell, args, n);
  315.         {
  316.             XFontStruct    *textFontStruct;
  317.             int        direction, ascent, descent;
  318.             XCharStruct    overall;
  319.             Position    topMargin, bottomMargin;
  320.  
  321.             infoDialogLabel = XtNameToWidget(infoDialog, "label");
  322.  
  323.             n=0;
  324.             XtSetArg(args[n], XtNfont, &textFontStruct);  n++;
  325.             XtGetValues(infoDialogLabel, args, n);
  326.             XTextExtents(textFontStruct, "mljf", 4,
  327.                 &direction, &ascent, &descent, &overall);
  328.  
  329.             width = overall.width*20;
  330.         }
  331.  
  332.     infoOkButton = XtCreateManagedWidget("ok", commandWidgetClass, 
  333.                     infoDialog, NULL, (Cardinal) 0);
  334.         XtAddCallback(infoOkButton, XtNcallback, infoOkProc, NULL);
  335.  
  336.         /* for ICCCM window manager protocol complience */
  337.  
  338.         XtOverrideTranslations (infoDialogShell,
  339.             XtParseTranslationTable ("<Message>WM_PROTOCOLS: ackInfo()"));
  340.  
  341.  
  342.     /* find the popup placement for this shell */
  343.  
  344.     {
  345.     popupPosResources *resourcePlacement;
  346.  
  347.     resourcePlacement = getPopupPosResources(
  348.             INFO_POPUP_NAME, POPUP_POS_CLASS, &placementInfo);
  349.     bcopy( (char *) resourcePlacement, (char *) &placementInfo,
  350.                 sizeof(popupPosResources) );
  351.     }
  352.  
  353. }
  354.  
  355.  
  356. /* displayInfo
  357.    enable popup dialog for saving files */
  358.  
  359. void
  360. displayInfo(infoText)
  361. char    *infoText;
  362. {
  363.     Arg        args[10];
  364.     Cardinal    n = 0;
  365.  
  366.  
  367.     n = 0;
  368.     XtSetArg(args[n], XtNlabel, infoText);  n++;
  369.     XtSetValues(infoDialog, args, n);
  370.  
  371.     n = 0;
  372.     XtSetArg(args[n], XtNwidth, width);  n++;
  373.     XtSetValues(infoDialogLabel, args, n);
  374.  
  375.  
  376.     positionAPopup(infoDialogShell, topLevel, &placementInfo);
  377.  
  378.  
  379.     XtPopup(infoDialogShell, XtGrabNone);
  380.  
  381.         /* for ICCCM window manager protocol complience */
  382.  
  383.         (void) XSetWMProtocols (XtDisplay(infoDialogShell),
  384.              XtWindow(infoDialogShell), &wmDeleteAtom, 1);
  385.     return;
  386. }
  387.